function _toConsumableArray(e) {
    return _arrayWithoutHoles(e) || _iterableToArray(e) || _nonIterableSpread();
}

function _nonIterableSpread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance");
}

function _iterableToArray(e) {
    if (Symbol.iterator in Object(e) || "[object Arguments]" === Object.prototype.toString.call(e)) return Array.from(e);
}

function _arrayWithoutHoles(e) {
    if (Array.isArray(e)) {
        for (var t = 0, r = new Array(e.length); t < e.length; t++) r[t] = e[t];
        return r;
    }
}

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var event = function() {
    var a = {}, u = {};
    return {
        listen: function(e, t) {
            if (e) {
                a[e] = a[e] || [], a[e].push(t);
                var r = u[e];
                r && (r.forEach(function(e) {
                    return e();
                }), u[e] = null);
            }
        },
        emit: function(e) {
            for (var t = this, r = arguments.length, n = new Array(1 < r ? r - 1 : 0), o = 1; o < r; o++) n[o - 1] = arguments[o];
            var i = a[e];
            if (!i || !i.length) return u[e] = u[e] || [], void u[e].push(function() {
                return t.emit.apply(t, [ e ].concat(_toConsumableArray(n)));
            });
            i.forEach(function(e) {
                "function" == typeof e && (n = n.map(function(e) {
                    return "function" == typeof e ? e : JSON.parse(JSON.stringify(e));
                }), e.apply(void 0, _toConsumableArray(n)));
            });
        },
        remove: function(e, t) {
            var r = a[e];
            if (r && r.length) if (t) {
                var n = r.indexOf(t);
                -1 !== n && r.splice(n, 1);
            } else r.length = 0;
        }
    };
}(), _default = {
    addListener: function(e, t) {
        return event.listen(e, t), this;
    },
    removeListener: function(e, t) {
        return event.remove(e, t), this;
    },
    emit: function(e) {
        for (var t = arguments.length, r = new Array(1 < t ? t - 1 : 0), n = 1; n < t; n++) r[n - 1] = arguments[n];
        return event.emit.apply(event, [ e ].concat(r)), this;
    },
    removeAllListener: function(e) {
        return event.remove(e), this;
    }
};

exports.default = _default;